package com.why.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.why.entity.Result;
import com.why.entity.User;
import com.why.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

/**
 * @author hy woo
 * @date 2022/6/3 12:12
 */
@Service("UserDetailsServiceImpl")
public class UserDetailsServiceImpl implements UserDetailsService {

    @Autowired
    UserMapper userMapper;

    @Override
    public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.eq("username",s);
        User user = userMapper.selectOne(wrapper);
        if (user==null){
            throw new UsernameNotFoundException("用户"+s+"不存在");
        }
        return user;
    }
}
